import Taro from "@tarojs/taro"
import { userAddress } from "./type"
export let UserId = {
  get() {
    return Taro.getStorageSync('userId')
  },
  set(value) {
    Taro.setStorageSync('userId', value)
  }
}
export let UserAddress = {
  get(type: "sender" | "recipient"): userAddress[] {
    return JSON.parse(Taro.getStorageSync(`${type}-address`) || '{}');
  },
  set(type: "sender" | "recipient", value: userAddress[]): void {
    let res: userAddress[] = UserAddress.get(type);
    res = res.concat(value);
    res = new Array(...new Set<userAddress>(res));
    Taro.setStorageSync(`${type}-address`, JSON.stringify(res));
  }
}
export function processCity(args: string[]) {
  let res = '';
  console.log(args);
  if (args.length <= 1) {
    return ''
  }
  if (args[0] === args[1]) {
    res = `${args[0]} ${args[2]} ${args[3] ? args[3] : ''}`;
  } else {
    res = `${args[0]} ${args[1]} ${args[2] ? args[2] : ''}`
  }
  return res;
}